package com.example.demo3.controller;

import com.example.demo3.entity.VO.Banner;
import com.example.demo3.service.IBannerService;
import com.example.demo3.utils.PageResult;
import com.example.demo3.utils.PassToken;
import com.example.demo3.utils.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * bannersController
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/system/banner")
public class BannersController
{
    @Autowired
    private IBannerService bannersService;
    @PassToken
    /**
     * 查询banners列表
     */
    @GetMapping("/list")
    public ServiceResponse list(Banner banners, @RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "3") int pageSize)
    {
        PageResult pageResult = bannersService.selectBannerList(banners,pageNum,pageSize);

        return ServiceResponse.createBySuccess(200,pageResult,"获取成功");
    }

    /**
     * 获取banners详细信息
     */
    @GetMapping(value = "/{id}")
    public ServiceResponse getInfo(@PathVariable("id") Long id)
    {
        return ServiceResponse.createBySuccess(200,bannersService.selectBannerById(id),"获取成功");
    }

    /**
     * 新增banners
     */
    @PostMapping
    public ServiceResponse add(@RequestBody Banner banners)   {
        int i = bannersService.insertBanner(banners);
        if(i>0){
            return ServiceResponse.createBySuccess(200,"","添加成功");
        }else{
            return  ServiceResponse.createByFail(500,"添加失败");

        }

    }
    /**
     * 修改banners
     */
    @PutMapping
    public ServiceResponse edit(@RequestBody Banner banners)
    {
        int i = bannersService.updateBanner(banners);
        if(i>0){
            return ServiceResponse.createBySuccess(200,"","添加成功");
        }else{
            return  ServiceResponse.createByFail(500,"添加失败");

        }
    }

    /**
     * 删除banners
     */
    @DeleteMapping("/{ids}")
    public ServiceResponse remove(@PathVariable Long[] ids)
    { int i = bannersService.deleteBannerByIds(ids);
        if(i>0){
            return ServiceResponse.createBySuccess(200,"","删除成功");
        }else{
            return  ServiceResponse.createByFail(500,"删除失败");

        }

    }
}
